package com.lightChat.netty;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * channel初始化器，当一个用户与服务器建立连接，就会初始化该用户的channel
 * 就会执行ChannelInitializer以及其子类中的初始化方法
 * @author sxt
 * @create 2019-11-13 20:38
 */
public class HelloChannelInitializer extends ChannelInitializer<SocketChannel> {



    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //通过socketChannel获取pipeline对象
        ChannelPipeline pipeline = socketChannel.pipeline();
        //添加了http的编码解码处理器
        pipeline.addLast("httpEncodeDecode", new HttpServerCodec());
        //添加自定义的处理器
        pipeline.addLast("customHandler",new CustomHandler());

    }
}
